package nl.hanze.designpatterns.mvc.view;

import java.awt.BorderLayout;

import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.border.EmptyBorder;

import com.jgoodies.forms.builder.PanelBuilder;
import com.jgoodies.forms.layout.CellConstraints;
import com.jgoodies.forms.layout.FormLayout;

import nl.hanze.designpatterns.mvc.controller.TroubleTicketController;
import nl.hanze.designpatterns.mvc.model.TroubleTicketModel;

public class TroubleTicketAddFormView extends View<TroubleTicketController, TroubleTicketModel> {

	private JTextField callerField;
	private JTextArea descriptionArea;
	private JButton submitButton;
	
	public TroubleTicketAddFormView(TroubleTicketController controller, TroubleTicketModel model) {
		super(controller, model);
		
		callerField = new JTextField();
		descriptionArea = new JTextArea();
		submitButton = new JButton("Submit");
		submitButton.setActionCommand("trouble_ticket_add");
		submitButton.addActionListener(controller);
		submitButton.putClientProperty("caller", callerField);
		submitButton.putClientProperty("description", descriptionArea);
		
		FormLayout layout = new FormLayout(
				"right:pref, 5dlu, 100dlu, 5dlu, 100dlu",
				"p, 5dlu, p, 5dlu, 50dlu, 5dlu, p");
		
		PanelBuilder builder = new PanelBuilder(layout);
		// Obtain a reusable constraints object to place components in the grid.
		CellConstraints cc = new CellConstraints();

		// Add a content to the form
		builder.addLabel("Caller",    cc.xy (1,  1));
		builder.addLabel("Description",    cc.xy (1,  3));
		builder.add(callerField, 		cc.xy(3, 1));
		builder.add(new JScrollPane(descriptionArea),	cc.xywh(3, 3, 3, 3));
		builder.add(submitButton, cc.xy(5, 7));
		
		BorderLayout border = new BorderLayout();
		this.setBorder(new EmptyBorder(5, 5, 5, 5));
		this.setLayout(border);
		
		add(builder.getPanel(), BorderLayout.WEST);
	}

	@Override
	public void notifyChange() {
		// TODO Auto-generated method stub

	}

}
